home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-05-02 | 1.3 KB | 60 lines | [TEXT/QED1] |
- // Copyright 1990 Waldemar Horwat.
- // Permission is granted for noncommercial use of this code.
-
- typedef int bool;
-
- struct StringData:HandleObject
- {
- int refCount;
- char str[1]; //Variable length
- };
-
- class String
- {
- private:
- StringData *data; // May be NIL!
-
- void internalCopy(const String &src);
- OSErr internalCopy(const char *cString);
- OSErr fresh();
-
- public:
- // Cumulative error.
- static OSErr err;
-
- // Constructors
- String() {data=0;}
- String(const String &src) {internalCopy(src);}
- String(const char *cString) {internalCopy(cString);}
-
- // Destructor
- ~String();
-
- // Clear the String to a null string.
- void clear();
-
- // Assignment operators
- String &operator=(const String &src);
- OSErr operator=(const char *cString);
-
- // Query functions.
- int length() const;
- char operator[](int index) const;
- String substr(int offset, int length) const;
- //Result may move when heap is scrambled!
- char *cString() const;
-
- bool operator==(const String &src2) const;
-
- // Concatenation
- String operator|(const String &src) const;
-
- // Appending data to the end
- OSErr operator|=(const String &src);
- OSErr operator|=(char ch);
- OSErr operator|=(char *cString);
- // Prepending data to the beginning
- OSErr operator^=(char ch);
- OSErr operator^=(char *cString);
- };
-